package com.example.controller;

import com.example.entity.BuyGoodsRequest;
import com.example.entity.ExchangeGoodsRequest;
import com.example.entity.Orders;
import com.example.entity.ScoreDetail;
import com.example.service.ScoreDetailService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.naming.spi.DirStateFactory;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/scoredetail")
public class ScoreDetailController {
    @Autowired
    private ScoreDetailService scoreDetailService;
    @RequestMapping("/list")
    public String list(Model model, @Param("uid")int uid){
        List<ScoreDetail> scoreDetailList = scoreDetailService.selectByUid(uid);
        model.addAttribute("scoreDetailList",scoreDetailList);
        return "student/scoredetail";
    }

//    // 购买商品（增加积分）
//    @PostMapping("/buyGoods")
//    public Result<Orders> buyGoods(@RequestBody BuyGoodsRequest request) {
//        try {
//            String  orders = scoreDetailService.buy(request.getUid(), request.getGid());
//            return Result.success(orders);
//        } catch (Exception e) {
//            return Result.error(e.getMessage());
//        }
//    }
//    // 使用积分兑换商品（减少积分）
//    @PostMapping("/exchange")
//    public Result<Orders> exchangeGoods(@RequestBody ExchangeGoodsRequest request) {
//        try {
//            String  orders = scoreDetailService.exchange(request.getUid(), request.getGid());
//            return Result.success(orders);
//        } catch (Exception e) {
//            return Result.error(e.getMessage());
//        }
//    }

}
